home *** CD-ROM | disk | FTP | other *** search
- #include "strtable.h"
-
- #define STEP 16 // Reallocation step
- #define LSTEP 4 // LOG
-
- KH_STRTABLE::KH_STRTABLE(int n, char** str)
- {
- strings = (char**)malloc((total = (n >> LSTEP << LSTEP) + STEP) * sizeof(char**));
- for(int i = 0; i < n; i++)
- {
- if(str == NULL)
- strings[i] = strdup("");
- else
- strings[i] = strdup(str[i]);
- }
- used = n;
- }
- ////////////////////////////////
- KH_STRTABLE::~KH_STRTABLE()
- {
- for(int i = 0; i < used; i++)
- delete strings[i];
- delete strings;
- }
- ////////////////////////////////
- int KH_STRTABLE::add(char* str)
- {
- if(used + 1 > total)
- {
- strings = (char**)realloc(strings, (total + STEP) * sizeof(char**));
- total += STEP;
- }
- strings[used] = strdup(str);
- used++;
- return used;
- }
- ////////////////////////////////
-